package com.lcxw.hxzbapi.dao.mapper;

import com.lcxw.hxzbapi.entity.pojo.Ticket;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface TicketMapper {

    //插入一个用户的抽奖券
    @Insert({
        "insert into ywpd_ticket (`userId`, ",
        "`lucky`, `diamond`)",
        "values (#{userId}, ",
        "#{lucky}, #{diamond})"
    })
    int insert(Ticket ticket);

    //通过用户的userId查询抽奖券
    @Select({
        "select",
        "*",
        "from ywpd_ticket",
        "where `userId` = #{userId}"
    })
    Ticket selectByUserId(Long userId);

    //通过userId更新用户的抽奖券
    @Update({
        "update ywpd_ticket",
        "set ",
        "`lucky` = #{lucky},",
        "`diamond` = #{diamond}",
        "where `userId` = #{userId}"
    })
    int updateTicket(Ticket ticket);

    @Update({
        "update ywpd_ticket",
        "set ",
        "`lucky` = lucky + #{lucky} ",
        "where `userId` = #{userId}"
    })
    int updateLuckyByUserId(Long userId, int lucky);

    @Update({
        "update ywpd_ticket",
        "set ",
        "`diamond` = diamond + #{diamond} ",
        "where `userId` = #{userId}"
    })
    int updateDiamondByUserId(Long userId, int diamond);
}
